#
# Copyright (C) 2009-2010 Jo-Philipp Wich <xm@subsignal.org>
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=nvram
PKG_RELEASE:=9

PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk
include $(TOPDIR)/package/triams/include/macrodef.mk

define Package/nvram
  SECTION:=base
  CATEGORY:=triams
  SUBMENU:=extern
  TITLE:=Userspace port of the Broadcom NVRAM manipulation tool
  MAINTAINER:=Jo-Philipp Wich <xm@subsignal.org>
  DEPENDS:= +libtds +libpthread +librt
endef

define Package/nvram/description
 This package contains an utility to manipulate NVRAM on VSPM310 based devices.
endef

define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) ./src/* $(PKG_BUILD_DIR)/
	$(CP) $(TOPDIR)/package/triams/include/ams_ipc_sem.h $(PKG_BUILD_DIR)/
endef

define Build/Configure
endef

define Package/nvram/config
	choice
    depends on PACKAGE_nvram
    prompt "nvram size"
    default PACKAGE_nvram_64k

    config PACKAGE_nvram_64k
      bool "64k size nvram"

    config PACKAGE_nvram_128k
      bool "128k size nvram"

    config PACKAGE_nvram_256k
      bool "256k size nvram"
  endchoice
endef

define Build/Compile
	$(MAKE) -C $(PKG_BUILD_DIR) \
		CC="$(TARGET_CC)" \
		CFLAGS="$(TARGET_CFLAGS) -Wall" \
		LDFLAGS="$(TARGET_LDFLAGS)"
	$(MAKE) -C $(PKG_BUILD_DIR) \
		DESTDIR="$(PKG_INSTALL_DIR)" \
		install
endef

define Build/InstallDev
	mkdir -p $(1)/usr/include
	$(CP)	$(PKG_INSTALL_DIR)/usr/include/nvram.h \
		$(1)/usr/include/
		$(CP)	$(PKG_INSTALL_DIR)/usr/include/sdinitvals.h \
		$(1)/usr/include/	
	mkdir -p $(1)/usr/lib
	$(CP)	$(PKG_INSTALL_DIR)/usr/lib/libnvram.so \
		$(1)/usr/lib/
	#$(CP)	$(PKG_INSTALL_DIR)/usr/lib/libnvram.a \
		$(1)/usr/lib/
endef


define Package/nvram/install
#	$(INSTALL_DIR) $(1)/etc/init.d
#	$(INSTALL_BIN) ./files/nvram.init $(1)/etc/init.d/nvram
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/nvram $(1)/usr/sbin/
	$(INSTALL_DIR) $(1)/usr/lib
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/libnvram.so $(1)/usr/lib/
#	$(INSTALL_BIN) $(PKG_BUILD_DIR)/libnvram.a $(1)/usr/lib/
endef

$(eval $(call BuildPackage,nvram))
